//
//  BQWelfareViewController.m
//  Adorable_Things
//
//  Created by ybq on 16/1/16.
//  Copyright © 2016年 Banana Inc. All rights reserved.
//

#import "BQWelfareViewController.h"
#import "BQWelfareListModel.h"
#import "BQNavViewCommon.h"

@interface BQWelfareViewController ()

@property (nonatomic, strong) BQNavViewCommon *navView;
@property (nonatomic, strong) BQWelfareListModel *model;
@property (weak, nonatomic) IBOutlet UIImageView *mainImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *rewardButton;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabels;


@end

@implementation BQWelfareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self requestData];
    [self createUI];
}

- (void)createUI {
    _navView = [[BQNavViewCommon alloc] initWithFrame:CGRectMake(0, 20, kWidth, 44)];
    [_navView.backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    _navView.titleLabel.text = @"福利";
    [self.view addSubview:_navView];

    
}

- (void)requestData {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"good_id"] = [NSString stringWithFormat:@"%@",_good_id];
    [manager POST:@"http://api.menghuoapp.com/v1/welfare_good/detail" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dataDic = responseObject[@"data"];
        _model = [[BQWelfareListModel alloc] init];
        [_model setValuesForKeysWithDictionary:dataDic];
        [_mainImageView sd_setImageWithURL:[NSURL URLWithString:_model.pic_url] placeholderImage:nil];
        _titleLabel.text = _model.title;
        _priceLabel.text = [NSString stringWithFormat:@"%@",_model.price];
        NSString *string = _model.desc;
        NSString *desc = [string substringWithRange:NSMakeRange(5, 31)];
        NSString *descs = [string substringWithRange:NSMakeRange(47, 21)];
        _descLabel.text = desc;
        _descLabels.text = descs;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)backButtonAction:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
